package com.baijing.springcloud.service;

import com.baijing.springcloud.domain.Person;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import feign.hystrix.FallbackFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Feign 负载均衡
 */
@Service
public class PersonHystrixService implements FallbackFactory<PersonService> {

    @Override
    public PersonService create(Throwable throwable) {
        return name -> {
            List<Person> list = new ArrayList<>();
            Person p = new Person("Person Service 故障");
            list.add(p);
            return list;
        };
    }
}
